package com.wqh.conformity.aop.aspect;

import com.wqh.conformity.aop.annotation.Log;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wqh
 */
@Aspect
@Component
@Slf4j
public class LogAspect {

    @AfterReturning("@annotation(logA)")
    public void afterSaveLog(JoinPoint joinPoint, Log logA)
    {
        String title = logA.title();
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        log.info(request.getRequestURI());
        log.info(request.getMethod());
        log.info(title);
    }
}
